//
//  main.m
//  04-HomeWork
//
//  Created by dllo on 16/7/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Color.h"
int main(int argc, const char * argv[]) {

    NSString *path = [NSString stringWithFormat:@"/Users/dllo/DLS160710/Objective-C/HomeWork/04-HomeWork/04-HomeWork/crayons.txt"];
    NSString *sourceStr = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
 //   NSLog(@"%@", sourceStr);
    NSArray *strArray = [sourceStr componentsSeparatedByString:@"\n"];
    NSMutableDictionary *colorDic = [NSMutableDictionary dictionary];
    NSArray *colorArray = [NSArray array];
    NSMutableArray *newArray = [NSMutableArray array];
    for (NSString *str in strArray) {
        colorArray = [str componentsSeparatedByString:@" #"];
        if (colorArray.count == 2) {
            NSString *colorStr = [colorArray objectAtIndex:0];
            NSString *codeStr = [colorArray objectAtIndex:1];
            [colorDic setObject:codeStr forKey:colorStr];
            Color *co = [[Color alloc]init];
            [co initWithName:colorStr ColorValue:codeStr];
            [newArray addObject:co];
    }
}
   // NSLog(@"%@",colorDic);
    //2.
    NSMutableDictionary *newDic = [NSMutableDictionary dictionary];
    for (Color *color in newArray) {
       NSString *capStr = [color sortKey:color];
        NSMutableArray *ColorArr = [newDic objectForKey:capStr];
        if (!ColorArr) {
            ColorArr = [NSMutableArray arrayWithObject:color];
            [newDic setObject:ColorArr forKey:capStr];
        } else {
         [ColorArr addObject:color];
        }
    }
    NSLog(@"%@",newDic);
    return 0;
}
